select      sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount)  OpenAmount
from  AR_STAR_Facts     a11
      join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
     where  a11.PayStatus in ('A')


select

 sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount )  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where  a11.PayStatus in ('A')
     and 
CustomerNUmberID=69910500000000001

--6990887

select
 sum(a11.GrossAmount)  GrossAmount,
  sum(a11.TransactionOpenAmount )  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where  a11.PayStatus in ('A')
     and 
CustomerNUmberID=36888130000000001


select [BusinessUnitCode],     sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount)  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
where a11.PayStatus in ('A')
group by [BusinessUnitCode]
order by [BusinessUnitCode]

sp_who2



select  sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount)  OpenAmount

from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where  a11.PayStatus in ('A')
AND	[BusinessUnitCode]='         058'


-- GrossAmount		OpenAmount
-- 836657.8600000	841264.4500000



select CustomerNumberID,[BusinessUnitCode], sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount)  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
where a11.PayStatus in ('A') and a11.TYPEID = 'I'
AND	[BusinessUnitCode] in ('         055','        1380','        1446','        1447','        1486','        1783')
group by 
CustomerNumberID,
[BusinessUnitCode]
order by [BusinessUnitCode],CustomerNumberID




select
 sum(a11.GrossAmount)  GrossAmount,
  sum(a11.TransactionOpenAmount )  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where  a11.PayStatus in ('A')
     and 
CustomerNUmberID=32078940000000001



select a11.paystatus,*
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where   
CustomerNUmberID=32078940000000001
and a11.PayStatus in ('A',' ')
order by a11.paystatus desc



a11.DateupdatedID,
select a11.paystatus, a11.FactsExtID, a11.CustomerNumberID, a11.DocumentNumber, a11.DocumentType, a11.TransactionOriginator, a11.InsertDate, a12.UserID,  LasttimeUpdated
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where   
CustomerNUmberID=32078940000000001
and a11.documentnumber=2501435
and a11.PayStatus in ('A',' ')
order by a11.paystatus desc

select
a11.DocumentNumber,
a11.DocumentType,
a11.PayItem,
a11.DocumentCompany,
a11.InternalPaymentID,
a11.FileLineIdentifier,
a11.InvoiceType,
a11.PayItemExtensionNumber,
a11.PayStatus,
a11.DateClosedID,
a11.InsertDate,
a11.ChangeDate,
a11.TransactionOriginator,
a12.UserID,
a12.ProgramID
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
Where   
CustomerNUmberID=32078940000000001
and a11.documentnumber=2501435
and a11.PayStatus in ('A',' ')
order by a11.paystatus desc       
        


select paystatus, * FROM ar_star_facts
where documentnumber='2501435' and documenttype='RU'

select * FROM dbo.JDEOWARLedger
where  AddressNumber=3207894 and DocumentType='RU'
DocumentNumber='2501435'



/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 
      [DocumentNumber]
      ,[DocumentType]
      ,[PayItem]
      ,[AddressNumber]
      ,[GLDate]
      ,[InvoiceDate]
      ,[BatchType]
      ,[BatchNumber]
      ,[BatchDate]
      ,[AccountID]
      ,[ParentNumber]
      ,[AlternatePayeeAddressNumber]
      ,[PayorAddressNumber]
      ,[GLPostedCode]
      ,[ARPostStatus]
      ,[BalancedJE]
      ,[PayStatus]
      ,[GrossAmount]
      ,[OpenAmount]
      ,[GLBankAccount]
      ,[AccountMode01]
      ,[GLCreditAccountID]
      ,[AccountMode02]
      ,[BusinessUnitCode]
      ,[ObjectAccount]
      ,[Subsidiary]
      ,[SubledgerType]
      ,[SubLedger]
      ,[PaymentTerms]
      ,[DueDate]
      ,[InvoiceNumber]
      ,[PONumber]
      ,[SalesDocumentNumber]
      ,[SalesDocumentType]
      ,[SalesOrderDocumentCompany]
      ,[OrderSuffix]
      ,[ClearedValueDate]
      ,[CommissionCode01]
      ,[AlphaName]
      ,[NumberOfPayments]
      ,[StatementNumber]
      ,[ClosedStatement]
      ,[ItemNumber]
      ,[Units]
      ,[UnitOfMeasure]
      ,[CashBasisAccountingPostCode]
      ,[DateInvoicePrinted]
      ,[TransactionOriginator]
      ,[UserID]
      ,[DateInvoiceClosed]
      ,[ProgramID]
      ,[DateUpdated]
      ,[LastTimeUpdated]
      ,[DeductionReasonCode]
      ,[WorkStationID]
  FROM [RD_DWCR].[dbo].[JDEOWARLedger]
  where
  addressnumber=3207894
  
  SELECT     *
  FROM [RD_DWCR].[dbo].[JDEOWARLedger]
  where
DocumentNumber=2501435 and documentType='RU'





select CustomerNumberID,[BusinessUnitCode], sum(a11.GrossAmount)  GrossAmount,
      sum(a11.TransactionOpenAmount)  OpenAmount
from  AR_STAR_Facts     a11
join  AR_STAR_FactsExt  a12
        on (a11.FactsExtID = a12.FactsExtID)
where a11.PayStatus in ('A') and a11.TYPEID = 'I'
AND	[BusinessUnitCode] in ('         055','        1380','        1446','        1447','        1486','        1783')
group by 
CustomerNumberID,
[BusinessUnitCode]
order by [BusinessUnitCode],CustomerNumberID